<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-global"></i>
          用户地址
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <!-- <div class="handle-box">
        <el-input v-model="search.mobile" placeholder="用户手机号" class="handle-input mr10" width="55"></el-input>
        <el-input v-model="search.userMobile" placeholder="经营人手机号" class="handle-input mr10" width="55"></el-input>
        <el-input v-model="search.userName" placeholder="经营人姓名" class="handle-input mr10" width="55"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
      </div> -->
      <el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
        <el-table-column prop="userName" label="实名人姓名"></el-table-column>
        <!-- <el-table-column prop="idCardType" label="证件类型"></el-table-column> -->
        <el-table-column prop="idCard" label="证件号"></el-table-column>
        <el-table-column prop="classifyPic" label="身份证正面">
          <template #default="scope">
            <el-image v-if="scope.row.idCardPic" class="table-td-thumb" :src="joinpic(scope.row.idCardPic)"></el-image>
            <el-tag v-else>无</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="申请时间" :formatter="dateFormat"></el-table-column>
        <el-table-column label="是否同意协议">
          <template #default="scope">
            <el-tag v-if="scope.row.isAgree == '0'">未同意</el-tag>
            <el-tag v-else>已同意</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="auditTime" label="审核时间" :formatter="dateFormat"></el-table-column>
        <el-table-column prop="statusRemarks" label="审核备注(拒绝理由)"></el-table-column>
        <el-table-column label="审核状态">
          <template #default="scope">
            <el-tag v-if="scope.row.isAudit == '0'">未审核</el-tag>
            <el-tag v-else-if="scope.row.isAudit == '1'">已通过</el-tag>
            <el-tag v-else>已拒绝</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template #default="scope">
            <el-button type="text" v-if="scope.row.isAudit == 0" icon="el-icon-edit" @click="pass(scope.$index, scope.row)">审核</el-button>
            <el-button type="text" v-if="scope.row.isAudit == 0" icon="el-icon-delete" class="red" @click="refuse(scope.$index, scope.row)">拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex" :page-size="query.pageSize" :total="pageTotal" @current-change="handlePageChange"></el-pagination>
      </div>
    </div>

    <!-- 编辑弹出框 -->
    <el-dialog title="" v-model="dialogVisible" width="65%">
      <img class="bigImage" :src="pic(dialogImageUrl)" alt="" />
    </el-dialog>
  </div>
</template>

<script>
import { api } from '../../api/index'
import { formatDate } from '../../common/data'
import moment from 'moment'
export default {
  inject: ['reload'],
  filters: {
    formatDate(time) {
      time = time * 1000
      let date = new Date(time)
      console.log(new Date(time))
      return formatDate(date, 'yyyy-MM-dd hh:mm')
    },
  },
  name: 'basetable',
  data() {
    return {
      query: {
        pageNo: 1,
      },
      search: {},
      tableData: [],
      // multipleSelection: [],
      showAddUser: false,
      pageTotal: 0,
      list: {},
      isChange: '',
      selectedOptions: [],
      dialogImageUrl: '',
      dialogVisible: false,
    }
  },
  created() {
    this.getData()
  },
  mounted() { },
  methods: {
    dateFormat: function (row, column) {
      var date = row[column.property]
      if (date == undefined) {
        return ''
      }
      return moment(date).format('YYYY-MM-DD HH:mm:ss')
    },
    joinpic(item) {
      return `https://mall.xiyibaomall.com/imgs/${item}`
    },
    //预览大图
    picPreview(file) {
      this.dialogImageUrl = file
      this.dialogVisible = true
    },

    // 获取分类列表
    getData() {
      api('/admin/subscribersCertification/list', {
        mobile: this.search.mobile,
        limit: 10,
        offset: this.query.pageNo,
      }).then((res) => {
        // console.log(res.data);
        this.tableData = res.data.rows
        this.pageTotal = res.data.total
      })
    },

    // 触发搜索按钮
    handleSearch() {
      this.getData()
    },

    // 编辑操作
    pass(index, row) {
      this.$prompt('请输入审核备注', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      })
        .then(({ value }) => {
          api('/admin/subscribersCertification/verify', {
            id: row.id,
            isAudit: 1,
            auditRemarks: value,
          }).then((res) => {
            if (res.code === 2000) {
              this.$message.success(res.message)
              this.reload()
            } else {
              this.$message.error(res.message)
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入',
          })
        })
    },
    refuse(index, row) {
      this.$prompt('请输入审核备注', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      })
        .then(({ value }) => {
          api('/admin/subscribersCertification/verify', {
            id: row.id,
            isAudit: 2,
            auditRemarks: value,
          }).then((res) => {
            if (res.code === 2000) {
              this.$message.success(res.message)
              this.reload()
            } else {
              this.$message.error(res.message)
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入',
          })
        })
    },
    //修改分类
    edit() {
      this.showAddUser = false
      api('/admin/subscribersCertification/verify', this.list).then((res) => {
        if (res.code === 2000) {
          this.$message.success('修改分类成功')
          this.list = {}
          this.reload()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    // 分页导航
    handlePageChange(val) {
      // console.log(val);
      this.query.pageNo = val
      this.getData()
    },
  },
}
</script>

<style lang="scss" scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}

.crop-demo {
  display: flex;
  align-items: flex-end;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  width: 178px;
  height: 178px;

  .pre-img {
    width: 178px;
    height: 178px;
    background: #f8f8f8;
    border: 1px solid #eee;
    border-radius: 5px;
    object-fit: cover;
  }

  .crop-input {
    position: absolute;
    width: 178px;
    height: 178px;
    left: 0px;
    top: 0px;
    opacity: 0;
    cursor: pointer;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
}

.bigImage {
  width: 100%;
}
</style>
